package com.itheima.d3_util;

import java.util.Random;

/**
 * 注册界面 : 随机产生6位验证码
 */
public class RegisterDemo {
    public static void main(String[] args) {
      /*  String code = "";
        String data = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

        Random r = new Random();
        // 2、开始定义一个循环产生每位随机字符
        for (int i = 0; i < 6; i++) {
            // 3、随机一个字符范围内的索引。
            int index = r.nextInt(data.length());
            // 4、根据索引去全部字符中提取该字符
            code += data.charAt(index); // code = code + 字符
        }
        System.out.println(code);*/
        Random random = new Random();
        String passWorld = "";


        while (true) {
            int num = random.nextInt(3);
            switch (num) {
                case 0:
                    char x = (char) ((char) random.nextInt(26) + 65);
                    passWorld += x;
                    break;
                case 1:
                    char y = (char) (random.nextInt(26) + 97);
                    passWorld+=y;
                    break;
                default:
                    break;
            }

            if (passWorld.length()==6){
                break;
            }
        }


        System.out.println(passWorld.toString());


    }
}
